setwd('~/Dropbox/02 Work/papers/populistturnout')

library(dplyr)
library(tidyr)
library(haven)
library(xtable)

#Figure 2: East Leave one out

read_dta('models/models_leaveoneout_east.dta') %>%
    mutate(coef = paste0(round(coef, 2), ifelse(pval < .05, '*',
                                     ifelse(pval < .1, '\textsuperscript{+}',
                                            '')))) %>%
    mutate(var = recode(var, `l_populistpresence` = 'Populist Representation',
                        `d_l_populistpresence` = '$\\Delta$ Populist Representation')) %>%
    select(country, var, coef) %>%
    rename(Country = country) %>%
    spread(key = var, value = coef) %>%
    xtable() %>% print(floating = F, booktabs = T, include.rownames = F,
                       file = 'tables/t_sensitivity_east.tex')

# Figure 3: Leave one out
read_dta('models/models_leaveoneout_lr.dta') %>%
    mutate(coef = paste0(round(coef, 2), ifelse(pval < .05, '*',
                                                ifelse(pval < .1, '\textsuperscript{+}',
                                                       '')))) %>%
    mutate(var = recode(var, `l_populistpresence_left` = 'Populist Representation (Left)',
                        `l_populistpresence_right` = 'Populist Representation (Right)',
                        `d_l_populistpresence_left` = '$\\Delta$ Populist Representation (Left)',
                        `d_l_populistpresence_right` = '$\\Delta$ Populist Representation (Right)')) %>%
    select(country, var, coef) %>%
    rename(Country = country) %>%
    spread(key = var, value = coef) %>%
    select(Country, `Populist Representation (Left)`,
           `Populist Representation (Right)`,
           `$\\Delta$ Populist Representation (Left)`,
           `$\\Delta$ Populist Representation (Right)`) %>%
    xtable() %>% print(floating = F, booktabs = T, include.rownames = F,
                       file = 'tables/t_sensitivity_lr_east.tex')